{template 'common/header'}
<link rel="stylesheet" type="text/css" href="../addons/{php echo $_GPC['m']}/resource/css/style.css" />
<link rel="stylesheet" type="text/css" href="../addons/{php echo $_GPC['m']}/resource/swal/dist/sweetalert2.min.css" />
<div class="panel panel-default">
    <div class="panel-heading">
        <h3 class="panel-title">
            订单
        </h3>
    </div>
    <div class="panel-body">
        <ul class="nav nav-tabs">
            <li role="presentation"><a href="{url 'site/entry/'.$_GPC['do'],array('m'=>$_GPC['m'],'version_id'=>$_GPC['version_id'])}">课程订单</a></li>
            <li role="presentation" class="active"><a>商城订单</a></li>
        </ul>
        <div class="ibox-content">
            <form action="{url 'site/entry/'.$_GPC['do'],array('m'=>$_GPC['m'],'version_id'=>$_GPC['version_id'])}" id="searchform" method="get">
                <input type="hidden" class="form-control" name="c" value="site">
                <input type="hidden" class="form-control" name="a" value="entry">
                <input type="hidden" class="form-control" name="do" value="{$_GPC['do']}">
                <input type="hidden" class="form-control" name="m" value="{$_GPC['m']}">
                <input type="hidden" class="form-control" name="version_id" value="{$_GPC['version_id']}">
                <div class="row" style="padding: 0 15px;">
                    <div class="col-sm-3">
                        <input type="text" class="form-control" placeholder="订单号" name="out_trade_no" value="{$out_trade_no}">
                    </div>
                    <div class="col-sm-3">
                        <input type="text" class="form-control" placeholder="用户id" name="openid" value="{$openid}">
                    </div>
                    <div class="col-sm-3">
                        <button type="submit" class="btn btn-default " style="margin-right:5px;">查询</button>
                    </div>
                </div>
            </form>
        </div>
        <form action="" method="post" class="form-horizontal form">
            <input type="hidden" name="token" value="{$_W['token']}">
            <div class="table-responsive panel-body">
                <table class="table-striped table-bordered table-hover dataTables-example table">
                    <thead class="navbar-inner">
                    <tr>
                        <th>项目信息</th>
                        <th>订单信息</th>
                        <th>用户信息</th>
                        <th>状态</th>
                        <th style="text-align:right;">操作</th>
                    </tr>
                    </thead>
                    <tbody id="level-list">
                    {loop $list $index $item}
                    <tr data-pei="{$item['pei']}">
                        <td><div class="type-parent">
                            商品：{$item['title']}<br/>
                            数量：{$item['total']}<br/>
                            {if $item['store']}
                            提货校区：{$item['store_name']}<br/>
                            {/if}
                        </div></td>
                        <td><div class="type-parent">
                            订单号：{$item['out_trade_no']}<br/>
                            微信订单号：{$item['wx_out_trade_no']}<br/>
                            应付款：{if $item['amount']}{$item['amount']}元{else}免费{/if}<br/>
                            {if $item['o_amount']}实付款：{$item['o_amount']}元<br/>{/if}
                            {if $item['coupon_price']}优惠：{$item['coupon_price']}元<br/>{/if}
                            配送方式：{if $item['pei_type']==1}商家配送{else if $item['pei_type']==2}自提{/if}<br/>
                            {if $item['fee']}运费：{$item['fee']}元<br/>{/if}
                            添加时间：{$item['createtime']}<br/>
                        </div></td>
                        <td><div class="type-parent">
                            用户id：{$item['openid']}<br/>
                            姓名：{$item['userinfo']['name']}<br/>
                            手机号：{$item['userinfo']['mobile']}<br/>
                            {if $item['userinfo']['address']}
                            地址:{$item['userinfo']['address']} {if $item['userinfo']['content']}{$item['userinfo']['content']}{/if}<br/>
                            {/if}
                            {if $item['content']}
                            备注：{$item['content']}<br/>
                            {/if}
                            {if $item['status']==2 && $item['tui_content']}
                            退款原因：{$item['tui_content']}
                            {/if}
                        </div></td>
                        <td><div class="type-parent" style="width: 100px;height: 32px;">
                            {if $item['status']==1}
                            {if $item['mall_type']==2}
                            {if $item['group_status']==-1}
                            <a class="btn   btn-xs btn-rounded btn-success">拼团中（{$item['group_list']['is_member']}/{$item['group_list']['member']}）</a>
                            {else if $item['group_status']==1}
                            {if $item['order_status']==-1}
                            <a class="btn   btn-xs btn-rounded btn-success">未核销</a>
                            {else}
                            <a class="btn   btn-xs btn-rounded btn-success">已核销</a>
                            {/if}
                            {/if}
                            {else}
                            {if $item['order_status']==-1}
                            <a class="btn   btn-xs btn-rounded btn-success">未核销</a>
                            {else}
                            <a class="btn   btn-xs btn-rounded btn-success">已核销</a>
                            {/if}
                            {/if}
                            {else if $item['status']==2}
                            {if $item['tui_status']==-1}
                            <a class="btn   btn-xs btn-rounded btn-success">退款中</a>
                            {else if $item['status']==1}
                            <a class="btn   btn-xs btn-rounded btn-success">已退款</a>
                            {/if}
                            {/if}
                        </div></td>
                        <td style="text-align:right;">
                            {if $item['status']==1}
                            {if $item['mall_type']==2}
                            {if $item['group_status']==1}
                            {if $item['order_status']==-1}
                            <a class="btn btn-primary btn-xs edit" data-id="{$item['id']}"><i class="fa fa-edit"></i>核销</a>
                            {/if}
                            {/if}
                            {else}
                            {if $item['order_status']==-1}
                            <a class="btn btn-primary btn-xs edit" data-id="{$item['id']}"><i class="fa fa-edit"></i>核销</a>
                            {/if}
                            {/if}
                            {else if $item['status']==2 && $item['tui_status']==-1}
                            <a class="btn btn-primary btn-xs tui" data-id="{$item['id']}"><i class="fa fa-edit"></i>退款</a>
                            {/if}
                        </td>
                    </tr>
                    {/loop}
                    </tbody>
                </table>
                <div style="text-align: right;">
                    {$pager}
                </div>
            </div>
        </form>
    </div>
</div>
<script>
    require(["../addons/{php echo $_GPC['m']}/resource/swal/dist/sweetalert2.min.js"],function(){
        var objc="";
        $(function(){
            //订单状态
            $("body").on("click",'.edit',function(){
                var that=this;
                objc=this;
                var id=$(this).attr("data-id");
                $.ajax({
                    type:"post",
                    url:"{url 'site/entry/'.$_GPC['do'],array('m'=>$_GPC['m'],'op'=>'orderchange','version_id'=>$_GPC['version_id'])}",
                    data:{id:id},
                    dataType:'json',
                    success:function(res){
                        if(res.status==1){
                            $(that).parent().prev().find("a").html('已核销');
                            $(that).remove();
                            swal('操作成功!', '操作成功!', 'success');
                        }else{
                            swal('操作失败!', '操作失败!', 'error');
                        }
                    }
                })
            });
            //删除
            $(".delete").click(function(){
                var that=$(this);
                var id=$(this).attr('data-id');
                swal({
                    title: '确定删除吗?',
                    text: "确定删除吗?",
                    type: 'warning',
                    showCancelButton: true,
                    confirmButtonColor: '#3085d6',
                    cancelButtonColor: '#d33',
                    confirmButtonText: '删除',
                    cancelButtonText: '取消',
                }).then(function(isConfirm) {
                    if (isConfirm) {
                        $.ajax({
                            type:"post",
                            url:"{url 'site/entry/'.$_GPC['do'],array('m'=>$_GPC['m'],'op'=>'delete','version_id'=>$_GPC['version_id'])}",
                            data:{id:id},
                            dataType:'json',
                            success:function(res){
                                if(res.status==1){
                                    swal('操作成功!', '操作成功!', 'success');
                                    that.parent().parent().remove();
                                }else{
                                    swal('操作失败!', '操作失败!', 'error');
                                }
                            }
                        })
                    }
                })
            });
            $("body").on('click','.tui',function(){
                var that=this;
                objc=this;
                var id=$(this).attr("data-id");
                $.ajax({
                    type:"post",
                    url:"{url 'site/entry/'.$_GPC['do'],array('m'=>$_GPC['m'],'op'=>'tui','version_id'=>$_GPC['version_id'])}",
                    data:{id:id},
                    dataType:'json',
                    success:function(res){
                        if(res.status==1){
                            $(that).parent().prev().find("a").html('已退款');
                            $(that).remove();
                            swal('操作成功!', '操作成功!', 'success');
                        }else{
                            swal('操作失败!',res.msg, 'error');
                        }
                    }
                })
            });
        })
    })
</script>
{template 'common/footer'}